<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>深拷贝-递归实现深拷贝</title>
</head>

<body>
  <script>
    // 递归实现深拷贝 - 简版实现对象和数组的拷贝
    const obj = {
      name: '佩奇',
      family: {
        father: '猪爸爸'
      },
      hobby: ['跳泥坑', '唱歌'],
    }

    // 封装深拷贝函数 cloneDeep()
    // function cloneDeep (data) {
    //   const newObj = Array.isArray(data) ? [] : {}
    //   // console.log(newObj)
    //   for (let k in data) {
    //     if (typeof data[k] === 'object'){
    //       newObj[k] = cloneDeep(data[k])
    //     } else {
    //       newObj[k] = data[k]
    //     }
    //   }
    //   return newObj
    // }
    // const res = cloneDeep(obj)
    // res.family.father = '你浅浅的微笑就像九转大肠'
    // console.log(res)
    // console.log(obj)


    function cloneDeep (data) {
      const newObj = Array.isArray(data) ? [] : {}
      for (let k in data[k] === 'object') {}
    }
  </script>
</body>

</html>